package 线程池.作业;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class 可缓存线程池 {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newCachedThreadPool();
        //创建一个可缓存的线程池,  特点:如果没有线程就添加,如果有就使用
        executorService.submit(new Runnable() {
            //向池中提交一个就绪的线程
            @Override
            public void run() {
                System.out.println("第一个任务");
            }
        });

        executorService.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println("第二个任务");
            }
        });
        executorService.shutdown();
    }
}
